package se.webbzon.boltzmann.minigame.animation;

import se.webbzon.boltzmann.minigame.sandbox.DefaultSandBoxAnimation;
import se.webbzon.boltzmann.minigame.sandbox.SandBoxAnimatable;

public class ResizeAnimation extends DefaultSandBoxAnimation {
	
	// The size of the picture
	private final double width, height;
	
	// The original size of the picture
	private double originalWidth, originalHeight;
	
	// The duration and remaining time
	private final int duration;
	private int remaining;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public ResizeAnimation(int duration, double width, double height) {
		this.width = width;
		this.height = height;
		this.duration = duration;
		remaining = duration;
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onStepEnd(SandBoxAnimatable picture) {
		if (duration == remaining) {
			originalWidth = picture.getWidth();
			originalHeight = picture.getHeight();
		}
		if (remaining > 0) {
			remaining--;
			float p = 1 - remaining / (float) duration;
			picture.setSize(originalWidth + (width - originalWidth) * p, 
							originalHeight + (height - originalHeight) * p);
		} else 
			notifyComplete();
	}

}
